Option Strict Off
Option Explicit On
Module BML
	Public COMPANYID As String
	Function Name(ByRef ID As Object, ByRef Typename_Renamed As Object) As Object
		Dim recName As ADODB.Recordset
		Name = ""
		If Typename_Renamed = "Vendor" Then
			recName = DBconn.Execute("Select * from AVM where VMVDN='" & ID & "'")
			If Not recName.EOF Then
				Name = recName.Fields("VMNME").Value
			End If
		Else
			recName = DBconn.Execute("Select * from RCM where CMCNO='" & ID & "'")
			If Not recName.EOF Then
				Name = recName.Fields("CMNME").Value
			End If
		End If
		recName.Close()
	End Function
	Function WareHouse(ByRef ID As Object) As Object
		Dim RecWareHouse As ADODB.Recordset
		RecWareHouse = "Select * from IWM where WMWHC='" & ID & "'"
		WareHouse = RecWareHouse.Fields("WMDSC").Value
		RecWareHouse.Close()
	End Function
	Function Effect(ByRef ID As Object) As Object
		Dim RecEffect As ADODB.Recordset
		RecEffect = DBconn.Execute("Select * from ITC where TCTTC='" & ID & "'")
		Effect = RecEffect.Fields("TCDSC").Value
		RecEffect.Close()
	End Function
	Sub WriteToFileIIM(ByRef ID As Object, ByRef WGT As Object, ByRef unit As Object, ByRef cost As Object, ByRef UpdateType As Object)
		Dim CostActual As Object
        Dim SQL As String = ""
		Select Case UpdateType
			Case "Recieved"
				SQL = "Update IIM set IMRCU=IMRCU+" & unit & ",IMRCW=IMRCW+" & WGT & ",IMLUS='" & UserLogin & "',IMLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "' Where IMITN='" & ID & "'"
			Case "Issued"
				SQL = "Update IIM set IMISU=IMISU+" & unit & ",IMISW=IMISW+" & WGT & ",IMYIU=IMYIU+" & unit & ",IMYIW=IMYIW+" & WGT & ",IMLUS='" & UserLogin & "',IMLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "' Where IMITN='" & ID & "'"
			Case "Adjusted"
				SQL = "Update IIM set IMAJU=IMAJU+" & unit & ",IMAJW=IMAJW+" & WGT & ",IMLUS='" & UserLogin & "',IMLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "' Where IMITN='" & ID & "'"
			Case "Sale"
				SQL = "Update IIM set IMSLU=IMSLU+" & unit & ",IMSLW=IMSLW+" & WGT & ",IMYSU=IMYSU+" & unit & ",IMYSW=IMYSW+" & WGT & ",IMLUS='" & UserLogin & "',IMLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "'" & " Where IMITN='" & ID & "'"
			Case "Opened"
				SQL = "Update IIM set IMOBU=IMOBU+" & unit & ",IMOBW=IMOBW+" & WGT & ",IMLUS='" & UserLogin & "',IMLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "' Where IMITN='" & ID & "'"
			Case "OnOrder"
				SQL = "Update IIM set IMOOW=" & WGT & ", IMOOU=" & unit & ",IMLUS='" & UserLogin & "',IMLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "' Where IMITN='" & ID & "'"
			Case "EffectCost"
				CostActual = CalculateCost(ID, WGT, unit, cost)
				SQL = "Update IIM set IMATC=" & CostActual & ",IMLUS='" & UserLogin & "',IMLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "' Where IMITN='" & ID & "'"
				
		End Select
		'MsgBox SQL
		DBconn.Execute(SQL)
		
		
	End Sub
	Sub WriteToILI(ByRef ID As Object, ByRef IDW As Object, ByRef IDL As Object, ByRef WGT As Object, ByRef unit As Object, ByRef UpdateType As Object)
		Dim RecILI As Object
        Dim SQL As String = ""
		RecILI = DBconn.Execute("Select * from ILI where ILITN='" & ID & "' AND ILWHC='" & IDW & "' and ILLOT='" & IDL & "'")
		If RecILI.EOF Then
			SQL = "INSERT ILI (ILITN,ILWHC,ILLOT,ILRID,ILLDT,ILLUS" & ",ILOBU,ILRCU,ILISU,ILAJU,ILSLU,ILYSU,ILYIU" & ",ILOBW,ILRCW,ILISW,ILAJW,ILSLW,ILYSW,ILYIW) VALUES " & "('" & ID & "','" & IDW & "','" & IDL & "','LI','" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "','" & UserLogin & "'" & ",0,0,0,0,0,0,0" & ",0,0,0,0,0,0,0)"
			DBconn.Execute(SQL)
		End If
		
		Select Case UpdateType
			Case "Recieved"
				SQL = "Update ILI set ILRCU=ILRCU+" & unit & ",ILRCW=ILRCW+" & WGT & ",ILLUS='" & UserLogin & "',ILLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "' " & " Where ILITN='" & ID & "' AND ILWHC='" & IDW & "' AND ILLOT='" & IDL & "'"
			Case "Issued"
				SQL = "Update ILI set ILISU=ILISU+" & unit & ",ILISW=ILISW+" & WGT & ",ILYIU=ILYIU+" & unit & ",ILYIW=ILYIW+" & WGT & ",ILLUS='" & UserLogin & "',ILLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "' " & " Where ILITN='" & ID & " 'AND ILWHC='" & IDW & "' AND ILLOT='" & IDL & "'"
			Case "Adjusted"
				SQL = "Update ILI set ILAJU=ILAJU+" & unit & ",ILAJW=ILAJW+" & WGT & ",ILLUS='" & UserLogin & "',ILLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "' " & " Where ILITN='" & ID & " 'AND ILWHC='" & IDW & "' AND ILLOT='" & IDL & "'"
			Case "Sale"
				SQL = "Update ILI set ILSLU=ILSLU+" & unit & ",ILSLW=ILSLW+" & WGT & ",ILYSU=ILYSU+" & unit & ",ILYSW=ILYSW+" & WGT & ",ILLUS='" & UserLogin & "',ILLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "' " & " Where ILITN='" & ID & "' AND ILWHC='" & IDW & "' AND ILLOT='" & IDL & "'"
			Case "Opened"
				SQL = "Update ILI set ILOBU=ILOBU+" & unit & ",ILOBW=ILOBW+" & WGT & ",ILLUS='" & UserLogin & "',ILLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "' " & " Where ILITN='" & ID & "' AND ILWHC='" & IDW & "' AND ILLOT='" & IDL & "'"
		End Select
		
		DBconn.Execute(SQL)
	End Sub
	Sub WriteToIWI(ByRef ID As Object, ByRef IDW As Object, ByRef WGT As Object, ByRef unit As Object, ByRef UpdateType As Object)
        Dim SQL As String = ""
		Dim RecIWI As ADODB.Recordset
		RecIWI = DBconn.Execute("Select * from IWI where IWITN='" & ID & "' and IWWHC='" & IDW & "'")
		If RecIWI.EOF Then
			SQL = "INSERT IWI (IWITN,IWWHC,IWRID,IWLDT,IWLUS" & ",IWOBU,IWRCU,IWISU,IWAJU,IWSLU,IWYSU,IWYIU" & ",IWOBW,IWRCW,IWISW,IWAJW,IWSLW,IWYSW,IWYIW) VALUES " & "('" & ID & "','" & IDW & "','WI','" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "','" & UserLogin & "'" & ",0,0,0,0,0,0,0" & ",0,0,0,0,0,0,0)"
			' MsgBox SQL
			DBconn.Execute(SQL)
		End If
		
		Select Case UpdateType
			Case "Recieved"
				SQL = "Update IWI set IWRCU=IWRCU+" & unit & ",IWRCW=IWRCW+" & WGT & ",IWLUS='" & UserLogin & "',IWLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "'" & " Where IWITN='" & ID & "' AND IWWHC='" & IDW & "'"
			Case "Issued"
				SQL = "Update IWI set IWISU=IWISU+" & unit & ",IWISW=IWISW+" & WGT & ",IWYIU=IWYIU+" & unit & ",IWYIW=IWYIW+" & WGT & ",IWLUS='" & UserLogin & "',IWLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "'" & " Where IWITN='" & ID & "' AND IWWHC='" & IDW & "'"
			Case "Adjusted"
				SQL = "Update IWI set IWAJU=IWAJU+" & unit & ",IWAJW=IWAJW+" & WGT & ",IWLUS='" & UserLogin & "',IWLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "'" & " Where IWITN='" & ID & "' AND IWWHC='" & IDW & "'"
			Case "Sale"
				SQL = "Update IWI set IWSLU=IWSLU+" & unit & ",IWSLW=IWSLW+" & WGT & ",IWYSU=IWYSU+" & unit & ",IWYSW=IWYSW+" & WGT & ",IWLUS='" & UserLogin & "',IWLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "'" & " Where IWITN='" & ID & "' AND IWWHC='" & IDW & "'"
			Case "Opened"
				SQL = "Update IWI set IWOBU=IWOBU+" & unit & ",IWOBW=IWOBW+" & WGT & ",IWLUS='" & UserLogin & "',IWLDT='" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "'" & " Where IWITN='" & ID & "' AND IWWHC='" & IDW & "'"
		End Select
		'MsgBox SQL
		DBconn.Execute(SQL)
	End Sub
	Function CalculateCost(ByRef Item As Object, ByRef WGT As Object, ByRef unit As Object, ByRef cost As Object) As Object
		Dim RecIIM As ADODB.Recordset
		Dim CodePer As String
		Dim QTYNew, QTYOnHand, ValueOnHand, ValueNew As Object
        'Dim value As Double
		RecIIM = DBconn.Execute("SELECT * from IIM where IMITN='" & Item & "'")
		CalculateCost = 0
		With RecIIM
			If Not .EOF Then
				CodePer = "Unt"
				QTYOnHand = .Fields("IMOBU").Value + .Fields("IMRCU").Value + .Fields("IMAJU").Value - .Fields("IMISU").Value
				QTYNew = unit
				
				If UCase(.Fields("IMPER").Value) = "WGT" Then
					CodePer = "Wgt"
					QTYOnHand = .Fields("IMOBW").Value + .Fields("IMRCW").Value + .Fields("IMAJW").Value - .Fields("IMISW").Value
					QTYNew = WGT
				End If
				ValueOnHand = QTYOnHand * .Fields("IMATC").Value
				ValueNew = QTYNew * cost
				CalculateCost = System.Math.Round((ValueOnHand + ValueNew) / (QTYOnHand + QTYNew), 2)
			End If
		End With
	End Function
	Sub ABCReport()
		Dim GroupB As Object
		Dim GroupA As Object
		Dim Group As Object
		Dim i As Object
		Dim SQL As Object
		Dim SQLDel As String
		Dim Recabc As ADODB.Recordset
		'Dim vtri As Integer
		
		SQLDel = "DELETE from ABC"
		DBconn.Execute(SQLDel)
		SQL = "Insert Into ABC (IMITN, IMITD,IMETD, IMPER, IMUMC, IMOBU, IMRCU, IMISU, IMAJU,IMSLU, " & "IMOBW, IMRCW, IMISW, IMAJW,IMSLW," & "OnhandU,OnhandW, IMATC)" & "SELECT IMITN, IMITD,IMETD, IMPER, IMUMC, IMOBU, IMRCU, IMISU, IMAJU, IMSLU," & "IMOBW, IMRCW, IMISW, IMAJW,IMSLU," & "IMOBU + IMRCU + IMAJU - IMISU ," & "IMOBW + IMRCW + IMAJW - IMISW , IMATC FROM IIM"
		DBconn.Execute(SQL)
		Recabc = New ADODB.Recordset
		Recabc.Open("SELECT ABC.* FROM ABC", DBconn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)
		Recabc.MoveFirst()
		Do While Not Recabc.EOF
			Recabc.Fields("value").Value = IIf(Recabc.Fields("IMPER").Value = "Wgt", Recabc.Fields("OnhandW").Value * Recabc.Fields("IMATC").Value, Recabc.Fields("OnhandU").Value * Recabc.Fields("IMATC").Value)
			Recabc.Update()
			Recabc.MoveNext()
		Loop 
		Recabc.Close()
		Recabc.Open("SELECT ABC.* FROM ABC order by value DESC", DBconn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)
		Recabc.MoveFirst()
		i = 0
		Do While Not Recabc.EOF
			i = i + 1
			Group = Recabc.Fields("value").Value
			Do While Recabc.Fields("value").Value = Group
				Recabc.Fields("IMORN").Value = i
				Recabc.Update()
				Recabc.MoveNext()
				If Recabc.EOF Then Exit Do
			Loop 
		Loop 
		Recabc.Close()
		GroupA = Int(10 * i / 100)
		GroupB = Int(30 * i / 100)
		' Insert GroupC
		
		SQL = "Update ABC Set ABC='C'"
		DBconn.Execute(SQL)
		' Insert GroupB
		SQL = "Update ABC Set ABC='B' where IMORN<=" & GroupB
		DBconn.Execute(SQL)
		' Insert GroupA
		SQL = "Update ABC Set ABC='A' where IMORN<=" & GroupA
		DBconn.Execute(SQL)
		
		
		
	End Sub
	Sub BBL510(ByRef Issue As String, ByRef InvNo As String)
		Dim Status As Object
		Dim SQL As Object
		Dim InvoiceNO As Object
		On Error GoTo bbl510_Err
		'Dim Tran_status As Boolean
		'Status = False
		If MsgBox("Do you really want to run CONVERT Order Packing Slip to Invoice ? ", MsgBoxStyle.YesNo, "BML") = MsgBoxResult.No Then Exit Sub
		Dim RecPrintSlip As Object
		Dim RecPrintSlip1 As ADODB.Recordset
		RecPrintSlip = DBconn.Execute("Select ECH.*,ECL.* FROM ECL LEFT OUTER JOIN " & " ECH ON ECL.ELODN = ECH.EHODN WHERE (ELSTT='3'or ELSTT='2' OR ELSTT='4')and(EHODN='" & Issue & "')  order by ECL.ELODN,ELOLN")
		Dim strBHIVN, ODN, WGT, BOStt, NotConfirm, QTY, strEHODN, LineNo As Object
		strEHODN = ""
		strBHIVN = ""
		'DBconn.BeginTrans
		'Tran_status = True
		
		With RecPrintSlip
			Do While Not .EOF 'Vong lap xet cho tung order cua khach hang
				ODN = !ELODN
				BOStt = 0
				NotConfirm = 0
				RecPrintSlip1 = DBconn.Execute("Select ECH.*,ECL.* FROM ECL LEFT OUTER JOIN " & " ECH ON ECL.ELODN = ECH.EHODN WHERE ELSTT='3' AND ELODN='" & ODN & "'")
				If Not RecPrintSlip1.EOF Then
					InvoiceNO = TakeOrderNumberACN("CNNIV", True)
					'Update BBH from ECH

					SQL = "Insert into BBH(BHLDT,BHDTE,BHITP" & ",BHIVN,BHCNO,BHSTN" & ",BHSTA,BHSNO,BHDUE,BHCPO" & ",BHORD,BHCCD,BHCER,BHNOL,BHSTT,BHFOD,BHVAN,BHVAT) values " & "('" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "','" & VB6.Format(!EHDTE, "yyyy-mm-dd hh:mm:ss") & "','" & !EHITP & "'" & ",'" & InvoiceNO & "','" & !EHCNO & "','" & !EHSTN & "'" & ",'" & !EHSTA & "','" & !EHSNO & "','" & VB6.Format(!EHDUE, "yyyy-mm-dd hh:mm:ss") & "','" & !EHCPO & "','" & !EHODN & "','" & !EHCCD & "','" & !EHCER & "','" & !EHNOL & "','1','Y',''," & !EHVAT & ")"
					strEHODN = strEHODN & IIf(strEHODN = "", "", ",") & !EHODN
					strBHIVN = strBHIVN & IIf(strBHIVN = "", "", ",") & InvoiceNO
					'MsgBox SQL
					DBconn.Execute(SQL)

				End If
				LineNo = 0
				Do While !ELODN = ODN 'Vong lap xet tung line trong tung order
					If !ELSTT = "3" Then 'Have Confirmed
						LineNo = LineNo + 1
						WGT = IIf(IsDBNull(!ELPSW), 0, !ELPSW)
						QTY = IIf(IsDBNull(!ELPSQ), 0, !ELPSQ)
						'                Update IIM
						'                SQL = "Update IIM set IMALW = IMALW + " & WGT & ",IMALU = IMALU +" & QTY & _
						''                    ",IMOOW =IMOOW - " & WGT & ",IMOOU = IMOOU -" & QTY & _
						''                    " WHERE IMITN='" & !ELITN & "'"
						'                MsgBox SQL
						'                DBconn.Execute SQL
						'
						'                Update BBL from ECL
						SQL = "Insert into BBL(BLIVN,BLLDT,BLITN,BLITD,BLLUS" & ",BLPER,BLLNE,BLSTT " & ",BLQTY,BLWGT,BLPRC,BLPDC,BLVAT" & ",BLAMT,BLBCA,BLWHC,BLLTN) values " & "('" & InvoiceNO & "','" & VB6.Format(Now, "yyyy-mm-dd hh:mm:ss") & "','" & !ELITN & "','" & !ELITD & "','" & UserLogin & "'" & ",'" & !ELPER & "','" & LineNo & "','1'" & "," & QTY & "," & WGT & "," & !ELPRC & "," & !ELPDC & "," & !ELVAT & "," & !ELAMT & "," & !ELBCA & ",'" & !ELWHC & "','" & !ELLTN & "')"
						'MsgBox !ELPSW
						DBconn.Execute(SQL)
						'Update ECL
						DBconn.Execute("Update ECL Set ELSTT='6' where ELODN='" & ODN & "' AND ELOLN='" & !ELOLN & "'")
					Else ' Trang thai chua confirm
						If !ELSTT = "4" Then 'Back order
							BOStt = BOStt + 1
							'DBconn.Execute "Update ECL Set ELSTT='4' where ELODN='" & !ELODN & "' AND ELOLN='" & !ELOLN & "'"
						Else
							If !ELSTT = "2" Then
								NotConfirm = NotConfirm + 1
								DBconn.Execute("Update ECL Set ELSTT='1' where ELODN='" & !ELODN & "' AND ELOLN='" & !ELOLN & "'")
							End If
						End If
					End If
					.MoveNext()
					If .EOF Then Exit Do
				Loop  'Ket thuc vong lap xet tung line trong tung order
				Status = "6"
				If NotConfirm > 0 Then Status = "1"
				If BOStt > 0 Then Status = "4"
				'Update ECH
				DBconn.Execute("Update ECH Set EHSTT='" & Status & "' where EHODN='" & ODN & "'")
			Loop  'Ket thuc vong lap xet cho tung order cua khach hang
		End With
		'DBconn.CommitTrans
		MsgBox("Completed! " & IIf(strEHODN = "", "", " Convert these Order No:" & Chr(13) & strEHODN & Chr(13) & " to Invoice No:" & Chr(13) & strBHIVN))
bbl510_Exit: 
		Exit Sub
		
bbl510_Err: 
		MsgBox(ErrorToString())
		'DBconn.RollbackTrans
		Resume bbl510_Exit
		
	End Sub
	Function GetTSQ(ByRef ID As Object) As Object
		Dim RecIIM As ADODB.Recordset
		RecIIM = New ADODB.Recordset
		RecIIM.Open("Select * from IIM WHERE IMITN='" & ID & "'", DBconn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)
		GetTSQ = RecIIM.Fields("IMTSQ").Value + 1
		RecIIM.Fields("IMTSQ").Value = GetTSQ
		RecIIM.Update()
	End Function
	
	Sub INV900()
		Dim SQL As Object
		Dim Response As Object
		Response = MsgBox("Are you sure to end closing in this PERIOD TIME?", MsgBoxStyle.YesNo + MsgBoxStyle.Critical + MsgBoxStyle.DefaultButton2, "Attention")
		If Response = MsgBoxResult.Yes Then
			'Update IIM
			SQL = "Update IIM set IMOBU=IMOBU+IMRCU-IMISU+IMAJU,IMRCU=0,IMISU=0,IMAJU=0" & ",IMOBW=IMOBW+IMRCW-IMISW+IMAJW,IMRCW=0,IMISW=0,IMAJW=0"
			DBconn.Execute(SQL)
			'Update Warehouse
			SQL = "Update IWI set IWOBU=IWOBU+IWRCU-IWISU+IWAJU,IWRCU=0,IWISU=0,IWAJU=0" & ",IWOBW=IWOBW+IWRCW-IWISW+IWAJW,IWRCW=0,IWISW=0,IWAJW=0"
			DBconn.Execute(SQL)
			'Update LOT
			SQL = "Update ILI set ILOBU=ILOBU+ILRCU-ILISU+ILAJU,ILRCU=0,ILISU=0,ILAJU=0" & ",ILOBW=ILOBW+ILRCW-ILISW+ILAJW,ILRCW=0,ILISW=0,ILAJW=0"
			DBconn.Execute(SQL)
		End If
	End Sub
	Sub INV910()
		Dim SQL As Object
		Dim Response As Object
		Response = MsgBox("Are you sure to end closing in this YEAR?", MsgBoxStyle.YesNo + MsgBoxStyle.Critical + MsgBoxStyle.DefaultButton2, "Attention")
		If Response = MsgBoxResult.Yes Then
			'Update IIM
			SQL = "Update IIM set IMOBU=IMOBU+IMRCU-IMISU+IMAJU,IMRCU=0,IMISU=0,IMAJU=0,IMYSU=0,IMYIU=0" & ",IMOBW=IMOBW+IMRCW-IMISW+IMAJW,IMRCW=0,IMISW=0,IMAJW=0,IMYSW=0,IMYIW=0"
			DBconn.Execute(SQL)
			'Update Warehouse
			SQL = "Update IWI set IWOBU=IWOBU+IWRCU-IWISU+IWAJU,IWRCU=0,IWISU=0,IWAJU=0,IWYSU=0,IWYIU=0" & ",IWOBW=IWOBW+IWRCW-IWISW+IWAJW,IWRCW=0,IWISW=0,IWAJW=0,IWYSW=0,IWYIW=0"
			DBconn.Execute(SQL)
			'Update LOT
			SQL = "Update ILI set ILOBU=ILOBU+ILRCU-ILISU+ILAJU,ILRCU=0,ILISU=0,ILAJU=0,ILYSU=0,ILYIU=0" & ",ILOBW=ILOBW+ILRCW-ILISW+ILAJW,ILRCW=0,ILISW=0,ILAJW=0,ILYSW=0,ILYIW=0"
			DBconn.Execute(SQL)
		End If
	End Sub
	Sub tam()
		Dim SQL As Object
		Dim Recabc As Object
		SQL = "UPDATE IWI Set  IWISW = IWISW + " & Recabc!BLWGT & ", IWISU = IWISU + " & Recabc!BLQTY & ", IWSLW = IWSLW + " & Recabc!BLWGT & ", IWSLU = IWSLU + " & Recabc!BLQTY & ", IWYIW = IWYIW + " & Recabc!BLWGT & ", IWYIU = IWYIU + " & Recabc!BLQTY & ", IWYSW = IWYSW + " & Recabc!BLWGT & ", IWYSU = IWYSU + " & Recabc!BLQTY & " where IWITN = '" & Recabc!BLITN & "'"
	End Sub
	Sub BBL900(ByRef InvoiceNO As String)
		Dim Objcmd As Object
		On Error GoTo bbl900_Err
		If MsgBox("Do you really want to run BBL900 ? ", MsgBoxStyle.YesNo, "BML") = MsgBoxResult.No Then
			Exit Sub
		End If
		Objcmd = New ADODB.Command
		Objcmd.CommandText = "sp_INV_regInvoice"
		Objcmd.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
		
		Objcmd.ActiveConnection = DBconn
		
		' Automatically fill in parameter info from stored procedure.
		Objcmd.Parameters.Refresh()
		' Set the param value.
		Objcmd(1) = InvoiceNO
		Objcmd(2) = UserLogin
		' Execute once and display...
		Objcmd.Execute()
		MsgBox("Registry Invoice NO. : " & InvoiceNO & " success")
bbl900_Exit: 
		Exit Sub
		
bbl900_Err: 
		MsgBox(ErrorToString())
		Resume bbl900_Exit
		
		
	End Sub
End Module